/*
 * FinanceFileChooser.java
 *
 *  
 */
package org.msb.finance.app;

import java.io.File;
import java.text.MessageFormat;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileSystemView;

/**
 * 
 * 
 * @author Marc Boudreau
 * 
 */
@SuppressWarnings("serial")
public class FinanceFileChooser extends JFileChooser {

	/*
	 * The suffix used for MSB Finance files.
	 */
	private static final String SUFFIX = ".fin"; //$NON-NLS-1$

	/**
	 * 
	 */
	public FinanceFileChooser() {
		this((File) null, null);
	}

	/**
	 * @param currentDirectoryPath
	 */
	public FinanceFileChooser(String currentDirectoryPath) {
		this(new File(currentDirectoryPath), null);
	}

	/**
	 * @param currentDirectory
	 */
	public FinanceFileChooser(File currentDirectory) {
		this(currentDirectory, null);
	}

	/**
	 * @param fsv
	 */
	public FinanceFileChooser(FileSystemView fsv) {
		this((File) null, fsv);
	}

	/**
	 * @param currentDirectory
	 * @param fsv
	 */
	public FinanceFileChooser(File currentDirectory, FileSystemView fsv) {
		super(currentDirectory, fsv);

		FileFilter filter = new FileFilter() {
			/*
			 * (non-Javadoc)
			 * 
			 * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
			 */
			@Override
			public boolean accept(File f) {
				return f.isDirectory() || f.getName().endsWith(SUFFIX);
			}

			/*
			 * (non-Javadoc)
			 * 
			 * @see javax.swing.filechooser.FileFilter#getDescription()
			 */
			@Override
			public String getDescription() {
				return MessageFormat.format(FinanceApp.getMessageResources().getString(
						"dialog.filechooser.financefile.description"), SUFFIX); //$NON-NLS-1$
			}
		};
		addChoosableFileFilter(filter);
		setAcceptAllFileFilterUsed(true);
		setFileFilter(filter);
		setMultiSelectionEnabled(false);
	}

	/**
	 * @param currentDirectoryPath
	 * @param fsv
	 */
	public FinanceFileChooser(String currentDirectoryPath, FileSystemView fsv) {
		this(new File(currentDirectoryPath), fsv);
	}
}
